let app = getApp()
//微信请求封装
function fetchApi(url, params, method = 'POST') {
	return new Promise((resolve, reject) => {
		// wx.showLoading({
		//   title: '加载中',
		// })
		wx.request({
			url: app.globalData.host + url,
			data: params,
			method,
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
        //"Content-Type": "applciation/json"
      },
			success: resolve,
			fail: reject
		})
	})
};

//微信showToast封装
function showToast(title, image, icon = 'success', ms = 1500) {
	return new Promise((resolve, reject) => {
		wx.showToast({
			title: title,
			duration: ms,
			icon,
			image: image,
			success: resolve,
			fail: reject
		})
	})
};


//微信showModal封装
function showModal(content, title = '提示') {
	return new Promise((resolve, reject) => {
		wx.showModal({
			title,
			content,
			success: resolve,
			fail: reject
		})
	})
};


//微信支付封装
function payment(t, n, p, s, ps) {
	return new Promise((resolve, reject) => {
		wx.requestPayment({
			timeStamp: t,
			nonceStr: n,
			package: p,
			signType: s,
			paySign: ps,
			success: resolve,
			fail: reject
		})
	})
};

//获取当前经纬度
function getLocation() {
	return new Promise((resolve, reject) => {
		wx.getLocation({
			type: 'wgs84',
			success: resolve,
			fail: reject
		})
	})
};




module.exports = {
	fetchApi,
	showToast,
	payment,
	showModal
}
